import { Body, Controller, Get, Post, Res, HttpStatus, UploadedFile, UseInterceptors, HttpException, Query, Request } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { Response } from 'express';
import { InternetCelebrity } from './internetCelebrity.entity';
import { InternetCelebrityService } from './internetCelebrity.service';
import {
  get
} from 'request'

import {join, resolve} from 'path'
import { createWriteStream } from 'fs';
import {
  wx_appid,
  wx_secret,
  wx_api
} from '../../setting'
import {
  existsSync,
  mkdirSync
} from 'fs'

import {
  apibefore
} from '../../router'
import { UserService } from '../user/user.service';
import { User } from '../user/user.entity';
import { ValidTokenInterceptor } from 'src/interceptor/validToken';
import { ValidRSAInterceptor } from 'src/interceptor/validRSA';
@Controller(apibefore('/internetCelebrity'))
@UseInterceptors(ValidTokenInterceptor)
@UseInterceptors(ValidRSAInterceptor)
export class InternetCelebrityController {
  constructor(private readonly internetCelebrityService: InternetCelebrityService
    ) {}

  @Get('/findAll')
  async findAll(@Query() params, @Request() req) {
    let wx_user: string = req.headers.wx_user
    return await this.internetCelebrityService.findAll_By_Platform(params.platform, wx_user)
  }

  @Post('create')
  async create(@Body() data: InternetCelebrity, @Request() req) {
    let wx_user = req.headers.wx_user
    console.log(wx_user,'sss')
    let addItem = new InternetCelebrity()
    addItem.wx_user = wx_user
    addItem.name = data.name
    addItem.platform = data.platform
    addItem.create_time = new Date()
    return await this.internetCelebrityService.create(addItem)
  }

  @Post('delete')
  async delete(@Body() data: InternetCelebrity){
    return await this.internetCelebrityService.remove(data.id)
  }

}
